package pl.pasu.mydiet.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import pl.pasu.mydiet.client.dto.DietPlanDTO;
import pl.pasu.mydiet.client.dto.DietUserDTO;

public class DietUser implements Serializable {
	private Long id;
	private String displayName;
	private String password;
	private Date created;
	private List<DietPlan> plans;

	public DietUser() {

	}

	public DietUser(Long id) {
		this.id = id;
	}

	public DietUser(DietUserDTO userDTO) {
		id = userDTO.getId();
		displayName = userDTO.getDisplayName();
		password = userDTO.getPassword();
		created = userDTO.getCreated();
		List<DietPlanDTO> dietDTOs = userDTO.getPlans();
		if (dietDTOs != null) {
			List<DietPlan> diets = new ArrayList<DietPlan>(dietDTOs.size());
			for (DietPlanDTO dietDTO : dietDTOs) {
				diets.add(new DietPlan(dietDTO));
			}
			this.plans = diets;
		}
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}

	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public List<DietPlan> getPlans() {
		return plans;
	}

	public void setPlans(List<DietPlan> plans) {
		this.plans = plans;
	}

	public void addPlan(DietPlan diet) {
		if (plans == null) {
			plans = new ArrayList<DietPlan>();
		}
		plans.add(diet);
	}

	public void removePlan(DietPlan diet) {
		if (plans == null) {
			return;
		}
		plans.remove(diet);
	}

}
